﻿using System.Net;
using System.IO;
namespace PowerSong.UserInterface
    {

    internal static class Infrastructure
        {

        internal const string WebsiteUrl = "http://www.powersong.org";

        internal const string FeedbackUrl = "http://www.nick-hill.com/powersong/Feedback.php";

        internal const string ReportErrorUrl = "http://www.nick-hill.com/powersong/ReportError.php";

        internal const string SubmitUrl = "http://www.nick-hill.com/powersong/Submit.php";

        internal const string DatabasesUrl = "http://www.nick-hill.com/powersong/Databases/{0}";

        internal static byte[] DownloadFile(string url)
            {

            // Send the request and accept a response
            var request = WebRequest.Create(url);
            using (var response = request.GetResponse())
                {
                using (var memory = new MemoryStream())
                    {

                    // Read the data
                    using (var stream = response.GetResponseStream())
                        {
                        var count = 0;
                        do
                            {
                            var buffer = new byte[1024];
                            count = stream.Read(buffer, 0, 1024);
                            memory.Write(buffer, 0, count);
                            }
                        while (stream.CanRead && count > 0);
                        }

                    // Return the result
                    return memory.ToArray();

                    }
                }

            }

        }

    }
